package com.sky.controller.user;

import com.sky.dto.OrdersPageQueryDTO;
import com.sky.dto.OrdersPaymentDTO;
import com.sky.dto.OrdersSubmitDTO;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.OrdersService;
import com.sky.vo.OrderPaymentVO;
import com.sky.vo.OrderSubmitVO;
import com.sky.vo.OrderVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.xmlbeans.impl.regex.REUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/user/order")
@Slf4j
@Api(tags = "订单相关接口")
public class OrdersController {
    @Autowired
    private OrdersService ordersService;
    @PostMapping("/submit")
    @ApiOperation("用户下单")
    public Result submit(@RequestBody OrdersSubmitDTO dto){
        log.info("用户下单{}",dto);
       OrderSubmitVO vo= ordersService.submit(dto);
        return Result.success(vo);
    }
    /**
     * 订单支付
     *
     * @param ordersPaymentDTO
     * @return
     */
    @PutMapping("/payment")
    @ApiOperation("订单支付")
    public Result<OrderPaymentVO> payment(@RequestBody OrdersPaymentDTO ordersPaymentDTO) throws Exception {
        log.info("订单支付：{}", ordersPaymentDTO);
        OrderPaymentVO orderPaymentVO = ordersService.payment(ordersPaymentDTO);
        log.info("生成预支付交易单：{}", orderPaymentVO);
        return Result.success(orderPaymentVO);
    }
     @ApiOperation("查看历史订单")
     @GetMapping("/historyOrders")
    public Result getHistoryOrders(OrdersPageQueryDTO dto){
        log.info("查看历史订单{}",dto);
      PageResult result= ordersService.getHistoryOrders(dto);
        return Result.success(result);
     }
     @ApiOperation("查询订单详情")
    @GetMapping("/orderDetail/{id}")
    public Result getOrderDetails(@PathVariable Long id){
        log.info("查询订单详情{}",id);
        OrderVO result= ordersService.getOrderDetails(id);
         return Result.success(result);
     }

    @ApiOperation("取消订单")
    @PutMapping("/cancel/{id}")
    public Result cancleOrder(@PathVariable Long id) throws Exception {
        log.info(" 取消订单{}",id);
        ordersService.cancleOrder(id);
        return Result.success();
    }
    @ApiOperation("再来一单")
    @PostMapping("/repetition/{id}")
    public Result repetition(@PathVariable Long id){
        ordersService.repetition(id);
        return Result.success();
    }
    @ApiOperation("用户催单")
    @GetMapping("/reminder/{id}")
    public Result reminder(@PathVariable Long id){
        log.info("用户催单{}",id);
        ordersService.reminder(id);
        return Result.success();
    }
}
